<template>
  <div>
    <FilterTable ref="table" columnsRef="jzyBrand" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)">
    </FilterTable>
    <div style="text-align:center">
      <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新建</el-button>
      <el-button size="small">保存</el-button>
      <el-button size="small">盘点确认</el-button>
      <el-button size="small">取消</el-button>
      <el-button size="small">打印</el-button>
      <el-button size="small">作废</el-button>
      <el-button size="small">一键赋值</el-button>
    </div>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <BrandModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getBrands } from '@/api/common/cars/brandcarsModels';
import BrandModal from './tabs/brandModal';

export default {
  name: 'Brand',
  components: {
    BrandModal
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', show: '显示' };
    return {
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: getBrands,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {}
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '优惠模式代码',
          dataIndex: 'DISCOUNT_MODE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '优惠模式说明',
          dataIndex: 'DISCOUNT_MODE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工时费优惠率',
          dataIndex: 'LABOUR_AMOUNT_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修材料费优惠率',
          dataIndex: 'REPAIR_PART_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售材料费优惠率',
          dataIndex: 'SALES_PART_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '附加费优惠率',
          dataIndex: 'ADD_ITEM_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '装潢工时费优惠率',
          dataIndex: 'UPHOLSTER_AMOUNT_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '装潢材料费优惠率',
          dataIndex: 'UPHOLSTER_PART_DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险类默认无优惠',
          dataIndex: 'NO_DISCOUNT_BY_INSURANCE',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}品牌`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
